<%-- 
    Document   : patient_detail
    Created on : 2016-3-13, 19:12:35
    Author     : Administrator
--%>

<%@page import="com.cxhd.pacs.DataConfig"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
         <title><%=DataConfig.getInstance().getConfig().get("systemName")%></title>
        <link rel="icon" href="${base}/favicon.ico" type="image/x-icon">
        <link href="${base}/css/patientDetail.css" rel="stylesheet" type="text/css" />
        <link href="${base}/css/font-awesome.css" rel="stylesheet" type="text/css" />


        <script type="text/javascript" src="${base}/js/jquery-1.9.1.js"></script>
        <script type="text/javascript" src="${base}/js/angular/angular.min.js"></script>
        <script type="text/javascript" src="${base}/js/jquery.cxhd.js"></script>
        <script type="text/javascript" src="${base}/js/bootstrap.min.js"></script>

    </head>
    <style>
        /*---滚动条默认显示样式--*/
        ::-webkit-scrollbar-thumb{
            background-color:#018EE8;
            height:50px;
            outline-offset:-2px;
            outline:2px solid #fff;
            -webkit-border-radius:4px;
            border: 2px solid #fff;
        }
        /*---鼠标点击滚动条显示样式--*/
        ::-webkit-scrollbar-thumb:hover{
            background-color:#FB4446;
            height:50px;
            -webkit-border-radius:4px;
        }
        /*---滚动条大小--*/
        ::-webkit-scrollbar{
            width:8px;
            height:8px;
        }
        /*---滚动框背景样式--*/
        ::-webkit-scrollbar-track-piece{
            background-color:#fff;
            -webkit-border-radius:0;
        }
        .xl_head th{
            border-top: 2px #000 solid;
            border-bottom: 2px #000 solid;
        }
    </style>
    <body ng-app="appDetail" ng-controller="mainCtrl" >
        <iframe ng-show="showzj" src="" id="iframepage2" name="iframepage2" height="550px" frameBorder=0 scrolling=auto width="100%"></iframe>
        <div ng-show="showTool"  id="mypage" class='info-head' style="zoom: 70%;font-size: 12px;padding-left: 25px;padding-top: 10px;padding-bottom: 10px;z-index: 1000;background-color: #cccccc;margin-bottom: 10px">
            <div style='float: left;margin-top: 10px'>
                <input ng-change="searchData()" ng-model="search.es" type='checkbox'>ES&nbsp;&nbsp;&nbsp;
                <input ng-change="searchData()" ng-model="search.mri" type='checkbox'>MRI&nbsp;&nbsp;&nbsp;
                <input ng-change="searchData()" ng-model="search.ct" type='checkbox'>CT&nbsp;&nbsp;&nbsp;
                <input ng-change="searchData()" ng-model="search.dx" type='checkbox'>DX&nbsp;&nbsp;&nbsp; 
                <input ng-change="searchData()" ng-model="search.us" type='checkbox'>US&nbsp;&nbsp;&nbsp; 
                <input ng-change="searchData()" ng-model="search.bingli" type='checkbox'>病历&nbsp;&nbsp;&nbsp;
                <input ng-change="searchData()" ng-model="search.yizhu" type='checkbox'>医嘱&nbsp;&nbsp;&nbsp; 
                <input ng-change="searchData()" ng-model="search.xindian" type='checkbox'>心电&nbsp;&nbsp;&nbsp; 
                <input ng-change="searchData()" ng-model="search.jianyan" type='checkbox'>检验&nbsp;&nbsp;&nbsp;
                <input ng-change="searchData()" ng-model="search.doc" type='checkbox'>文档&nbsp;&nbsp;&nbsp;
                <input ng-change="searchData()" ng-model="search.remoteRpt" type='checkbox'>远程报告

            </div>
            <div style="float:left ;margin-left: 10px">
                <a id="openW" href="" ng-click="addParam()" target="_blank" class="btn btn-success btn-sm" style="">远程报告</a>
            </div>

            <div style="float:left ;margin-left: 10px">
                <a id="openW" href="" ng-click="addDoc()" target="_blank" class="btn btn-success btn-sm" style="">添加文档</a>
            </div>
            <div id="ask" style="float:left ;margin-left: 10px">
                <button ng-click="sendNotice()" class="btn btn-success btn-sm" style="">发送请求</button>
            </div>

            <div id="ask" style="float:left ;margin-left: 10px">
                <button ng-click="sendZhuanZhen()" class="btn btn-success btn-sm" style="">发送转诊</button>
            </div>
            <div style="float:left ;margin-left: 5px">
                <button ng-show="detail_other"  ng-click="paste_detail()" class="btn btn-success btn-sm" style="">粘贴</button>
            </div>
            <div style="float:left ;margin-left: 5px">
                <button id="sendComputer" style="display: none"  onclick="openWebs()" class="btn btn-success btn-sm" style="">发送到电脑</button>
            </div>
            <div style='clear: both'></div>
        </div>
        <div class="content">
            <div class="wrapper">
                <!--                <div class="light"><i></i></div>-->
                <hr class="line-left">
                <hr class="line-right">
                <div class="main">
                    <h1 class="title">{{name}}的医疗信息</h1>
                    <!--<div style="display: none">{{blist| myFilter:search}}</div>-->
                    <div ng-repeat=" list in listed" class="year" repeatFinish >
                        <h2><a onclick='$(this).parents(".year").toggleClass("close");' href="#">{{list.year}}<i></i></a></h2>
                        <div class="list">
                            <ul>
                                <li id='{{item.time_id}}' class="cls"  ng-repeat="item in list.content" style="cursor: pointer" >
                                    <p ng-dblclick="checkItem(item, $event)" class="date" >{{item.month}}</p>
                                    <p ng-click="show_detail(item)" class="intro">{{item.department}}({{item.event_name}})</p>
                                    <p ng-dblclick="cut_detail(item)" style="float: left;font-size: 18px;line-height: 32px;color: #63d029;">{{item.hospital_name}}</p>
                                    <p class="version">&nbsp;</p>
                                    <div ng-click="show_detail(item)" class="more">
                                        <p style="color: #cc00ff">{{item.event_description}}</p>

                                        <p>{{item.event_result}}</p>
                                    </div>
                                </li>


                            </ul>
                        </div>
                    </div>

                </div>
            </div>
        </div>
        <!--        <div class="footer">
                    <div class="footer-content clearfix">
                        <div class="copyright"> Copyright © 2011-2014  All Rights Reserved </div>
                    </div>
                </div>-->


        <div class="modal fade bs-example-modal-lg show_big_image" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
            <div class="modal-dialog modal-lg" style="width:100%">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 style="float: left" class="modal-title" id="gridSystemModalLabel">{{name}}@{{showTitle}}</h4>
                        <button ng-click="printData()" class="btn btn-sm btn-success " style="padding: 0px;padding-left: 5px;padding-right: 5px;float: left;font-size: 10px;margin-right: 10px;" >打印</button>
                        &nbsp;&nbsp;
                        <button ng-show="imageDetailStatus" ng-click="rotateImage(90)" class="btn btn-sm btn-success " style="padding: 0px;padding-left: 5px;padding-right: 5px;float: left;font-size: 10px;margin-right: 10px;" >正转90</button>
                        &nbsp;
                        <button ng-show="imageDetailStatus" ng-click="rotateImage(-90)" class="btn btn-sm btn-success " style="padding: 0px;padding-left: 5px;padding-right: 5px;float: left;font-size: 10px;margin-right: 10px;" >反正90</button>

                        <div style="clear: both"></div>
                    </div>
                    <div id="myRpt" class="modal-body" style="min-height: 400px;overflow: auto">
                        <div id="mod2"  class="mod-2" style="width: 100%">

                            <img  ng-repeat="rimage in resultImages" ng-click="selectOneImage('image' + $index)" style="display: block;max-width: 100%;margin-left: auto;margin-right: auto;max-height: 100%" id="image{{$index}}" ng-src="{{rimage}}" alt="">

                        </div>
                        <div id="mod1" class="mod-1" style="font-size: 18px;overflow: auto">
                            <table class="table">
                                <tr ng-repeat="re in results">
                                    <td>{{re}}</td>
                                </tr>
                            </table>

                        </div>
                        <div id="mod3"  class="mod-3" style="display: none;min-width: 400px;font-size: 12px;overflow: auto">
                            <table width="100%" style="border-spacing:0px">
                                <tr>
                                    <td colspan="5" align="right" >时间：{{lisResults[0].date_test}}</td>
                                </tr>
                                <tr class="xl_head">
                                    <th>简称</th>
                                    <th>检验项目</th>
                                    <th>结果</th>
                                    <th>参考范围</th>
                                    <th>单位</th>
                                </tr>
                                <tr ng-repeat="re in lisResults">
                                    <td align="center">{{re.item_code}}</td>
                                    <td align="center">{{re.item_name}}</td>
                                    <td align="center">{{re.test_value}}&nbsp;{{re.text_node}}</td>
                                    <td align="center">{{re.text_range}}</td>
                                    <td align="center">{{re.text_danwei}}</td>
                                </tr>
                            </table>

                        </div>

                        <div id="mod4"  class="mod-4" style="overflow-x: hidden;overflow-y: auto">


                        </div>
                    </div>

                </div>
            </div>
        </div>



        <!--        <div class="showDetail" style="display: none">
                    <div class="xl-head">
                        <div class="xl-content">
                            <span ng-click="openView()" style="font-weight: bold;color: #0074D9;font-size: 20px">{{name}}@{{showTitle}}</span>
                        </div>
                        <button ng-click="printData()" style="float: left" class="btn btn-sm btn-success">打印</button>
                        <div ng-click="close();" class="xl-close"><span class="fa fa-close"></span></div>
                        <div  style='clear: both'></div>
                    </div>
                    <div id="rpt" class="container" style="max-width: 1200px; margin-left: auto;margin-right: auto;margin-bottom: 20px;overflow-y: auto">
        
                        <div class="mod-2" style="width: 100%">
        
                            <img style="max-width: 100%;margin-left: auto;margin-right: auto;max-height: 100%" id="imageDetail" src="" alt="">
        
                        </div>
                        <div class="mod-1" style="font-size: 18px;overflow: auto">
                            <table class="table">
                                <tr ng-repeat="re in results">
                                    <td>{{re}}</td>
                                </tr>
                            </table>
        
                        </div>
                        <div class="mod-3" style="min-width: 400px;font-size: 12px;overflow: auto">
                            <table width="100%" style="border-spacing:0px">
                                <tr>
                                    <td colspan="5" align="right" >时间：{{lisResults[0].date_test}}</td>
                                </tr>
                                <tr class="xl_head">
                                    <th>简称</th>
                                    <th>检验项目</th>
                                    <th>结果</th>
                                    <th>参考范围</th>
                                    <th>单位</th>
                                </tr>
                                <tr ng-repeat="re in lisResults">
                                    <td align="center">{{re.item_code}}</td>
                                    <td align="center">{{re.item_name}}</td>
                                    <td align="center">{{re.test_value}}&nbsp;{{re.text_node}}</td>
                                    <td align="center">{{re.text_range}}</td>
                                    <td align="center">{{re.text_danwei}}</td>
                                </tr>
                            </table>
        
                        </div>
        
                        <div class="mod-4" style="overflow: auto">
        
        
                        </div>
                    </div>
                </div>-->
    </body>
</html>

<script>
    var patientName = "<%= request.getAttribute("patientName")%>";
    var vhost_id = "<%= request.getAttribute("host_id")%>";
    var vitem = JSON.parse('<%= request.getAttribute("item")%>');
    var timeId = "<%= request.getAttribute("time_id")%>";
    var flag = "<%= request.getAttribute("flag")%>";
    var zjurl = "<%= DataConfig.getInstance().getZjurl()%>";
    //console.log(patientData);
    angular.module("appDetail", [])
            .directive('repeatFinish', function () {
                return {
                    link: function (scope, element, attr) {
                        console.log(scope.$index)
                        if (scope.$last == true) {
                            console.log('ng-repeat执行完毕');
                            //向父控制器传递事件
                            scope.$emit('$repeatFinish');
                            //向子控制器传递事件
                            // scope.$broadcast('$repeatFinish');
                        }
                    }
                }
            })
            .controller("mainCtrl", function ($scope) {

                $scope.listed = [];
                $scope.search = {};
                $scope.blist = [];
                $scope.viewOther;
                $scope.dus = 0;
                $scope.showId;
                $scope.openView = function () {
                    // if (!$scope.viewOther) {
                    $scope.viewOther = window.open("viewOther.jsp");
//                    }
//                     if($scope.viewOther.closed){
//                           $scope.viewOther = window.open("viewOther.jsp");
//                        }
                    setTimeout(function () {

                        console.log($scope.viewOther.getParentData($scope.item));
                    }, 200);

                }

                $scope.cut_detail = function (item) {
                    item.patientName = $scope.name;
                    steveConfrim("确定剪切吗？", function () {
                        tools.setCookie("detail_pk", JSON.stringify(item));
                    });
                };



                $scope.rotateImage = function (du) {
                    $scope.dus = $scope.dus + du;
                    $("#" + $scope.image_id).css("transform", "rotate(" + $scope.dus + "deg)");
                }

                $scope.paste_detail = function () {
                    var items = tools.getCookie("detail_pk");
                    items = JSON.parse(items);

                    steveConfrim("确定粘贴【" + items.patientName + "(" + items.event_name + ")】到这里吗？", function () {
                        //console.log({pk: items.pk, host_id: $scope.item.host_id});
                        $.post("paste_detail", {pk: items.pk, host_id: $scope.item.host_id}, function (data) {
                            tools.delCookie("detail_pk");
                            if (data == 'true') {
                                window.location.reload();
                            }
                        })
                    })
                }
                $scope.getDetail = function (hostId) {
                    $.post("getDetails", {host_id: hostId}, function (data) {
                        if (data) {
                            $scope.blist = data;
                            $scope.$apply();
                            var str = {};
                            for (i in data) {
                                var year = ST_date.getYearBy_cn(data[i].event_time);
                                if (!str[year]) {
                                    str[year] = {};
                                }
                                var syear = str[year];
                                syear['year'] = year;

                                if (!syear['content']) {
                                    syear['content'] = [];
                                }
                                data[i].month = ST_date.getDayBy_cn(data[i].event_time);
                                data[i].time_id = data[i].event_time.split(" ")[0];
                                syear['content'].push(data[i]);

                            }
                            for (q in str) {
                                $scope.listed.push(str[q]);



                                setTimeout(function () {

                                    if (timeId != 'null') {
                                        $("html,body").animate({scrollTop: $("#" + timeId).offset().top}, 10);
                                    }
                                }, 500);
                                cssChange.initC();

                            }
                            console.log($scope.listed.length);
                            if ($scope.listed.length > 0) {

                                $scope.showTool = true;
                            }
                            $scope.$apply();
                            // console.log(str);
                        }

                    });
                };
                $scope.image_id = "image0";
                $scope.selectOneImage = function (id) {
                    $scope.image_id = id;
                }

                $scope.printData = function () {

                    var obj = document.getElementById($scope.showId);
                    var newWindow = window.open("打印窗口", "_blank");//打印窗口要换成页面的url
                    var docStr = obj.innerHTML;
                    newWindow.document.write(docStr);
                    newWindow.document.close();
                    newWindow.print();
                    newWindow.close();


                }
                $scope.searchData = function () {
                    var filter = [];
                    //console.log($scope.search);
                    for (s in  $scope.search) {
                        if (!$scope.search[s]) {
                            continue;
                        }
                        if (s == 'dx') {
                            filter.push("DX");
                        } else if (s == 'us') {
                            filter.push("US");
                        } else if (s == 'es') {
                            filter.push("ES");
                        } else if (s == 'ct') {
                            filter.push("CT");
                        } else if (s == 'mri') {
                            filter.push("MRI");
                        } else if (s == 'bingli') {
                            filter.push("病历");
                        } else if (s == 'yizhu') {
                            filter.push("医嘱");
                        } else if (s == 'jianyan') {
                            filter.push("检验");
                        } else if (s == 'xindian') {
                            filter.push("心电");
                        } else if (s == 'doc') {
                            filter.push("其它文档");
                        } else if (s == 'remoteRpt') {
                            filter.push("远程诊断报告");
                        }
                    }
                    var newData = [];
                    var newDataFormat = [];
                    if (filter.length > 0) {
                        for (n in  $scope.blist) {
                            if (filter.indexOf($scope.blist [n].event_name) > -1) {
                                newData.push($scope.blist [n]);
                            }
                        }
                    } else {
                        if (newData.length == 0) {
                            newData = $scope.blist;
                        }
                    }
                    var str = {};
                    for (i in newData) {
                        var year = ST_date.getYearBy_cn(newData[i].event_time);

                        if (!str[year]) {
                            str[year] = {};
                        }
                        var syear = str[year];
                        syear['year'] = year;

                        if (!syear['content']) {
                            syear['content'] = [];
                        }
                        newData[i].month = ST_date.getDayBy_cn(newData[i].event_time);
                        syear['content'].push(newData[i]);
                    }
                    for (q in str) {
                        newDataFormat.push(str[q]);
                    }

                    $scope.listed = newDataFormat;

                    cssChange.initC();

                };

                $scope.checkItem = function (item, event) {
                    steveConfrim("确定删除吗？", function () {
                        $.post("deleteItem", {pk: item.pk}, function (data) {
                            if (data == 'true') {
                                steveAl("删除成功", 1000);
                                setTimeout(function () {
                                    location.reload();
                                }, 1000);
                            }
                        })
                    });
                }
                $scope.addParam = function () {
                    window.open("remoteRpt.jsp?data=" + encodeURIComponent(JSON.stringify(item)));
                    // $("#openW").attr("src",);
                    return true;

                }
                $scope.addDoc = function () {
                    window.open("uploadDoc.jsp?data=" + encodeURIComponent(JSON.stringify(item)));
                    // $("#openW").attr("src",);
                    return true;

                }
                $scope.show_detail = function (item) {

                    $(".modal").modal("show");
                    $scope.item = item;
                    $scope.showTitle = item.event_name + "(" + item.event_description + ")";
                    if (item.result_type == "image") {
                        $(".mod-2").show();
                        $scope.imageDetailStatus = true;
                        $scope.showId = "mod2";
                        $(".mod-1,.mod-3,.mod-4").hide();
                        $scope.resultImages = item.event_result.split(",");
                        for (var i in $scope.resultImages) {
                            $scope.resultImages[i] = "getImage?fileId=" + $scope.resultImages[i];
                        }
                        // $("#imageDetail").attr("src", "getImage?fileId=" + item.event_result);
                    } else if (item.result_type == 'table') {
                        $scope.imageDetailStatus = false;
                        if (item.data_type == 'lis_detail') {
                            $(".mod-3").show();
                            $scope.showId = "mod3";
                            $(".mod-2,.mod-1,.mod-4").hide();
                            $.post("getLisResult", {pk: item.pk}, function (data) {

                                if (data) {
                                    $scope.lisResults = data;
                                    $scope.$apply();
                                }
                            })
                        }

                    } else {
                        $scope.imageDetailStatus = false;
                        $.post("getResult", {pk: item.pk, type: item.result_type}, function (data) {

                            if (data) {
                                if (item.result_type == 'html') {

                                    $(".mod-4").show();
                                    $scope.showId = "mod4";
                                    $(".mod-2,.mod-3,.mod-1").hide();
                                    $(".mod-4").html(unescape(data));
                                    setTimeout(function () {

                                        $(".series_institution").parent().prependTo($("#paper"));
                                    }, 500);
                                } else {
                                    $(".mod-1").show();
                                    $scope.showId = "mod1";
                                    $(".mod-2,.mod-3,.mod-4").hide();
                                    $scope.results = data.split("@");
                                    //console.log($scope.results);
                                }
                                $scope.$apply();
                            }
                        })
                    }
                    // $(".showDetail").toggle();
                }
                $scope.close = function () {
                    $(".showDetail").toggle();
                }

                //发送转诊请求
                $scope.sendZhuanZhen = function () {
                    if ($scope.showzj) {
                        $scope.showzj = false;
                    } else {
                        $scope.showzj = true;
                        $("#iframepage2").attr("src", zjurl + $scope.item.host_id);
                    }
                    console.log($scope.showzj);

                }


                $scope.sendNotice = function () {
                    //  console.log({host_id: $scope.item.host_id, name: $scope.item.name, sex: $scope.item.sex, age: $scope.item.age});
                    // return;
                    $.post("sendNotice", {host_id: $scope.item.host_id, name: $scope.item.name, sex: $scope.item.sex, age: $scope.item.age}, function (data) {
                        if (data == 'true') {
                            steveAl("发送成功", 1000);
                        } else {
                            steveAl("发送失败!", 1000);
                        }

                    })

                }


                setTimeout(function () {

                    try {
                        item = parent.window.getDetail();
                        $scope.item = item;
                        $scope.name = item.name;
                        $scope.$apply();
                        $scope.getDetail(item.host_id);
                    } catch (e) {
                        $scope.name = patientName;
                        $scope.item = vitem;
                        item = vitem;
                        $scope.$apply();
                        $scope.getDetail(vhost_id);
                    }

                    $scope.detail_other = tools.getCookie("detail_pk");
                    console.log($scope.detail_other + "-------------------");
                }, 200);



            })

    var cssChange = {
        initC: function () {
            $(".main .year .list").each(function (e, target) {
                var $target = $(target),
                        $ul = $target.find("ul");
                $target.height($ul.outerHeight()), $ul.css("position", "absolute");
            });

        }
    }
    function autoHeight() {
        var bHeight = $(window).height();

        $("#myRpt").height(bHeight - 180);

    }
    autoHeight();

    $(document).keydown(function (event) {

        if (event.keyCode == 27) {
            // $(".showDetail").hide();
            $(".modal").modal("hide");
        }
    });

    $(window).resize(function () {
        autoHeight();
    });


    var web;
    var login = function () {
        if (!web) {
            web = new WebSocket("ws://60.161.186.217:33888/websocket");
        }
        web.onopen = function () {
            console.log("open");
            var msg = {};
            msg.type = "openChrome";
            msg.body = "http://192.168.197.217/MedicalInfo/patient/openDetail?host_id=" + vhost_id + "&flag=1";
            // alert(JSON.stringify(room));
            // web.send(JSON.stringify(room));
            web.send(JSON.stringify(msg));
        }


        web.onmessage = function (e) {

            console.log(e.data);
            //  parseMessage(JSON.parse(e.data));

        };

        web.onclose = function (e) {
            web = null;
            console.log("close");
        };
        web.onerror = function (e) {

        };
    }
    if (patientName && patientName != 'null') {
        $("#ask").hide();
        if (vhost_id && vhost_id != 'null' && flag != "1") {
            $("#sendComputer").show();
        }
    }
    function openWebs() {
        login();
    }


</script>
